<?php 
namespace Home\Controller;
use Think\Controller;
class LoginController extends Controller{
	public function index(){
		$this->display();
	}

	public function verify(){ 
		$Verify = new \Think\Verify();  
	    $Verify->fontSize = 18;  
	    $Verify->length   = 4;  
	    $Verify->useNoise = false;  
	    $Verify->codeSet = '0123456789';  
	    $Verify->imageW = 130;  
	    $Verify->imageH = 50;  
	    $Verify->entry(1); 
	}

	public function check(){
		$verify = new \Think\Verify(); 
		$code=$_POST[fcode];		
        $r=$verify->check($code,1);
        if(!$r){
            $this->error('验证码错误',U('index'));
        }else{
        	$user=M('admin');
        	// $_POST['password']=($_POST[password]);
        	 // var_dump($_POST);
        	 $userinfo['admin_name']=$_POST['username'];
        	 $userinfo['admin_password']=$_POST['password'];

        	if($rst=$user->where($userinfo)->find()){
        		// echo $user->getLastSql();
				$_SESSION['login']=1;
				$_SESSION['username']=$_POST['username'];
				$_SESSION['admin']=$rst['admin_is_super'];
				// var_dump($_SESSION);
				// var_dump($rst);
				if($rst["admin_is_super"]){
					$this->success('登录成功',U('Index/index'));
				}else{
					$this->error('您的权限不足!',U('index'));
				}
			}else{
				$this->error('用户名或密码有误',U('index'));
			} 
		}
	}

	public function logout(){
		setcookie(session_name(),'',time()-3600,'/');
		session_unset();
		session_destroy();

		$this->success('退出成功',U('index'));
	}
}
 ?>